package net.sansi.v3correctserver.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sansi.v3correctserver.dto.R;
import net.sansi.v3correctserver.dto.v3serverapi.V3ServerApiBrightnessDto;
import net.sansi.v3correctserver.service.brightness.BrightnessService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;

@Api(tags = "亮度控制接口")
@RestController
@RequestMapping("/brightness")
@Validated
public class BrightnessController {

    @Resource
    private BrightnessService brightnessService;

    @ApiOperation("获取整屏亮度")
    @GetMapping("/bright")
    public R<V3ServerApiBrightnessDto.bright> bright(@RequestParam("screenId") @NotBlank String screenId) {
        return R.data(brightnessService.bright(screenId));
    }

    @ApiOperation("修改整屏亮度")
    @PutMapping("/bright")
    public R<V3ServerApiBrightnessDto.updateResp> brightnessUpdate(@RequestParam("screenId") @NotBlank String screenId, @RequestBody V3ServerApiBrightnessDto.bright data) {
        return R.data(brightnessService.brightUpdate(screenId, data));
    }

    @Resource
    HttpServletRequest request;

    @ApiOperation("获取亮度控制方式")
    @GetMapping("/brightMethod")
    public R<V3ServerApiBrightnessDto.brightMethod> brightnessMethod(@RequestParam("screenId") @NotBlank String screenId) {
        return R.data(brightnessService.brightMethod(screenId));

    }

    @ApiOperation("修改亮度控制方式")
    @PutMapping("/brightMethod")
    public R<V3ServerApiBrightnessDto.updateResp> brightMethodUpdate(@RequestParam("screenId") @NotBlank String screenId, @RequestBody V3ServerApiBrightnessDto.brightMethod data) {
        return R.data(brightnessService.brightMethodUpdate(screenId, data));
    }

    @ApiOperation("校正控制开关查询")
    @GetMapping("/correctSwitch")
    public R<V3ServerApiBrightnessDto.brightCorrection> brightCorrectQuery(@RequestParam("screenId") @NotBlank String screenId) {
        return R.data(brightnessService.brightCorrect(screenId));
    }

    @ApiOperation("校正开关状态设置")
    @PutMapping("/correctSwitch")
    public R<V3ServerApiBrightnessDto.updateResp> brightCorrectUpdate(@RequestParam("screenId") @NotBlank String screenId, @RequestBody V3ServerApiBrightnessDto.brightCorrection data) {
        return R.data(brightnessService.brightCorrectUpdate(screenId, data));
    }
}
